/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jard.webshop.jsfbeans;

import jard.webshop.management.UserManagement;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.inject.Named;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Harteex
 */
@ManagedBean(name = "registerController")
@RequestScoped
public class RegisterController {
    @ManagedProperty(value="#{registerBacking}")
    private RegisterBacking backingBean;
    @ManagedProperty(value = "#{userModelBean}")
    private UserModelBean sessionUser;

    /** Creates a new instance of RegisterController */
    public RegisterController() {
    }

    public RegisterBacking getBackingBean() {
        return backingBean;
    }

    public void setBackingBean(RegisterBacking backingBean) {
        this.backingBean = backingBean;
    }

    public UserModelBean getSessionUser() {
        return sessionUser;
    }

    public void setSessionUser(UserModelBean sessionUser) {
        this.sessionUser = sessionUser;
    }
    
    public String doRegister() {
        System.out.print("TESTESTESTESTESTSETETSETESTSETEST????");
        if (backingBean == null)
            System.out.println("null");
        else {
            System.out.println("OK!");
            System.out.println("user.password=" + backingBean.getUser().getPassword());
        }
        
        UserManagement.getInstance().addUser(backingBean.getUser());
        
        sessionUser.setUser(backingBean.getUser());
        
        return "success";
    }
}
